<?php

namespace app\admin\controller;

use app\common\controller\BaseAdminController;
use app\Request;

class Index extends BaseAdminController
{
    protected $noNeedLogin = ['login'];

    public function index()
    {
        if($this->request->isAjax()){
            $rule = $this->auth->getRule(true);
            $user = $this->auth->getUser();
            return $this->success('获取成功',['rule'=>$rule,'user'=>$user]);
        }
        return $this->view->fetch();
    }
    public function test()
    {
        return json(['code'=>1,'msg'=>'test']);
    }
    public function login()
    {
        if($this->request->isAjax()){
            $data = $this->request->param();
            $res = $this->auth->login($data['username'],$data['password']);
            if($res===false){
                return $this->error($this->auth->getError());
            }
            return $this->success('登录成功');
        }
//        echo "<pre>";
//        print_r($this->view);
//        exit;
        return $this->view->fetch();
    }
    public function logout()
    {
        $res = $this->auth->logout();
        if($res){
            return $this->success('退出成功');
        }
        return $this->error('退出失败');
    }
    public function get_icon()
    {
        return $this->view->fetch();
    }
}